<template>
  <div>
      <h2>一起来学习Axios</h2>
  </div>
</template>

<script>
import axios from "axios";

// var HTTP = axios.create({
//     baseURL:'https://www.easy-mock.com/mock/5b56c24f34c1d075b3b438db/axios/',
//     responseType:'json',
//     timeout:1000,  // 设置请求时间
//          params:{
//     book:"123"
//     },
//     headers:{      // 请求头
//           'custome-header': 'miaov',
//      }
// })

// 并发请求
var HTTP = axios.create({
  baseURL: "https://www.easy-mock.com/mock/5b56c24f34c1d075b3b438db/axios/"
});

export default {
  created() {
    function http1() {
      return HTTP.get("axios1");
    }

    function http2() {
      return HTTP.post("axios2");
    }

    //    axios.all([http1(),http2()]).then(axios.spread((res1,res2)=>{
    //        console.log(res1.data)
    //        console.log(res2)
    //    }))

    axios.all([http1(), http2()]).then(
      axios.spread((res1, res2) => {
        console.log(res1.data);
        console.log(res2);
      })
    );
  }
};
</script>
<style scope>
h2 {
  text-align: center;
}

/*
  created(){
      this.$http.get('https://www.easy-mock.com/mock/5b56c24f34c1d075b3b438db/axios/axios1')
      .then((response)=>{
            console.log(response.data)
        })
      .catch((error) =>{
        console.log(error)
    })
  }

          */

/*
                axios.get('https://www.easy-mock.com/mock/5b56c24f34c1d075b3b438db/axios/axios1')
                .then((Response)=>{
                    console.log(Response.data)
                })
                .catch((error)=>{
                    console.log(error)
                })
            */
/*
                 HTTP.get("axios1")
                .then((Response)=>{
                    console.log(Response.data)
                })
                .catch((error)=>{
                    console.log(error)
                })
            */
</style>



